

*** THis do file generates Kaitz indicies by state group and year using all individuals ages 16 and over and the original policy categories

* If needed change global path to point to directory where files are stored on your computer
*global path "I:/DataSets5/Duncan/Dropbox/Recent Minimum Wage Changes/2020.12 NBER Update/JOLE Precommittment Replication"
global dtadir "$path/Data"
global tabdir "$path/Tables"
global figdir "$path/Figures"
global estdir "$path/Estimates"
global logdir "$path/Logfiles"


* Kaitz index time series
log using "$logdir/kaitz-index-time-series-cep-categories.log", replace


*** Assemble relevant years of the basic monthly CPS. Keep all ages for this
use "${path}/Data/CPS-2019-no-restrictions.dta", clear

drop if year < 2011

* Drop age under 16
drop if age < 16

drop if empstat == 0

*** Construct economic outcomes of interest 

* if empstat = 10: "At work"
* if empstat = 12: "employed, not at work last week

gen employed = 0
replace employed = 1 if  empstat == 10 |  empstat == 12

*** Assume that armed forces are employed
replace employed = 1 if empstat == 1

**** Construct education variables
gen dropout = 0 
replace dropout = 1 if educ < 73
gen highschool = 0 
replace highschool = 1 if educ == 73
gen somecollege = 0
replace somecollege = 1 if educ >= 81 & educ <= 92
gen collegeplus = 0
replace collegeplus = 1 if educ >= 111

gen quarter = 1 if inlist(month,1,2,3)
replace quarter = 2 if inlist(month,4,5,6)
replace quarter = 3 if inlist(month,7,8,9)
replace quarter = 4 if inlist(month,10,11,12)

gen time = (100*year) + month


* Clean usual hours worked ORG
*** Generate hours worked variable. Use hours worked in the previous week.
*** If people are NIU recode hours worked as 0.
*** If people are in the armed forces assume they work 40 hours per week.
*** Topcode hours worked at 100 per week
gen workhrs = uhrsworkorg
replace workhrs = 0 if uhrsworkorg >= 998
*replace workhrs = 40 if uhrsworkorg == 999 & empstat == 1
*replace workhrs = 100 if workhrs > 100

*** Merge in HPI data
merge m:1 statefip year quarter using "${path}/Data/HPI_2019.dta"
drop if _merge == 2
drop _merge

replace HPI = HPI/1000

*** Merge in personal income data
merge m:1 statefip year quarter using "${path}/Data/PersonalIncome_2019.dta"
gen lnPersonalIncome = ln(PersonalIncome)
drop if _merge == 2
drop _merge

** creates mid-skill employment rate 
gen group = 0 
replace group = 1 if (age <= 30 & age > 21 & highschool == 1) | (age > 30 & age <= 45 & dropout == 1) | (age > 45 & age < 65 & dropout == 1) 

egen stateempD = mean(employed) if group == 1, by(year month statefip) 
egen stateempE = max(stateempD), by(year month statefip) 

gen lowskill = 0 
replace lowskill = 1 if inrange(age,16,25) & dropout == 1

gen young = 0 
replace young = 1 if inrange(age,16,21)

gen primeage = 0
replace primeage = 1 if inrange(age,26,54)

*** Generate indicators if receive tips/overtime, paid hourly, or have wage rates imputed
gen tippedorovertime = otpay == 2
gen hourly = paidhour == 2 
gen notimputed = qhourwag == 0 
gen notimputedB = (qhourwag == 0 & qearnwee == 0)

* Calculate hourly wage for generating Kaitz Index
gen hrwage = hourwage

*** Keep only people eligible for the ORG sample for hourly wage regressions
replace hrwage =. if eligorg != 1

*** Keep only people are employed for hourly wage regressions
replace hrwage =. if employed != 1

* For individuals paid by the hour, calculate hourly wage as usual weekly earnings / usual weekly hours
replace hrwage = earnweek/uhrsworkorg if hourly == 2  

*** Keep only people who do not have imputed wage rates for hourly wage regressions
replace hrwage =. if notimputed != 1

* Adjust NIU cases for hourly wages for hourly wage regressions
replace hrwage =. if hourwage == 999.99

gen acs = 0
gen cps = 1

gen perwt = wtfinl

* Generate median hourly wage by state
*collapse (p50) median_wage=hrwage [pw=earnwt], by(statefip year)

compress
*
* merge in policy categories 
cap drop originaltype-increase5 
merge m:1 statefip using "${path}/Data/min_wage_variables_for_ACS_and_CPS_analysis.dta", nogen keepusing(originaltype jan*min) 

cap drop indexer StatIncreaserLarge StatIncreaserSmall statutoryincreasein2014or2015 statutoryincreasein2014to2017 statutoryincreasein2014to2018

gen indexer = 0 
gen StatIncreaserLarge = 0 
gen StatIncreaserSmall = 0 
gen statutoryincreasein2014or2015 = 0
gen statutoryincreasein2014to2018 = 0

* CEP Categories
replace indexer = 1 if originaltype == "Indexer" 
replace statutoryincreasein2014or2015 = 1 if (jan2016min - jan2013min) > 0 & indexer == 0 
replace StatIncreaserLarge = 1 if indexer == 0 & (jan2015min - jan2013min) >= 1 & (jan2016min - jan2013min) != . 
replace StatIncreaserSmall = 1 if indexer == 0 & statutoryincreasein2014or2015 == 1 & StatIncreaserLarge == 0 

* Generate January minimum wage variable
gen effectiveminwage =.
forvalues i=2011/2019 {
	replace effectiveminwage = jan`i'min if year == `i'
}

* Generate policygroup variable for doing proportional sampling correctly
gen policygroup = 1
replace policygroup = 2 if indexer == 1
replace policygroup = 3 if StatIncreaserSmall == 1
replace policygroup = 4 if StatIncreaserLarge == 1

compress
*/
gen median_wage =.

levelsof statefip, local(states) 

* Generate median wage state and year with appropriate weight
foreach state of local states {
	forvalues i = 2011/2019 {
		qui sum hrwage if statefip == `state' & year == `i' [aw=earnwt], detail
		qui replace median_wage = r(p50) if statefip == `state' & year == `i'
	}
}

gen kaitz_state = effectiveminwage/median_wage

sum kaitz_state, detail


merge m:1 statefip using "${path}/Data/state_fips_master.dta"
drop _merge



tab kaitz_state if year == 2011

tab kaitz_state if year == 2019

rename state_abbr state



*** Index by Policy Group

preserve

egen medianwageA = wtmean(median_wage), by(policygroup year) weight(earnwt)
egen medianwageB = max(medianwageA), by(policygroup year)

* Generate Minimum Wage by group
egen minimumwageA = wtmean(effectiveminwage), by(policygroup year) weight(perwt)
egen minimumwageB = max(minimumwageA), by(policygroup year)

* Generate Kaitz Index
gen kaitz_index = minimumwageB/medianwageB

collapse medianwageB minimumwageB kaitz_index, by(policygroup year)

reshape wide medianwageB minimumwageB kaitz_index, i(year) j(policygroup)

foreach var in medianwageB minimumwageB kaitz_index {
label var `var'1 "No Change"
label var `var'2 "Indexer"
label var `var'3 "Statutory Increaser Under $1"
label var `var'4 "Statutory Increaser $1 or More"
}

*
grstyle init
grstyle color background white
*grstyle graphsize x 7
*grstyle graphsize y 4
grstyle set legend, nobox

graph drop _all
 
* Ratio of Minimum to Median
graph twoway scatter kaitz_index1 year, msize(medlarge) lwidth(thin) lcolor(blue) mcolor(blue) connect(direct) ||  ///
            scatter kaitz_index2 year, msize(large) lwidth(thick) lcolor(bluishgray) mcolor(bluishgray) connect(direct)   ||  ///
            scatter kaitz_index3 year, msymbol(Dh) msize(medlarge) lwidth(thick) lcolor(navy) mcolor(navy) connect(direct) || ///
			scatter kaitz_index4 year, msymbol(Dh) msize(medium) lwidth(medium) lcolor(midblue) mcolor(midblue) connect(direct) ///
name(kaitz_index, replace) title("Panel B: Kaitz Index by Minimum Wage Policy Category", size(medsmall)) ///
ytitle("Index") ylabel(0.50(.05)0.75, gmin gmax) ///
xlabel(2011(2)2019) scale(0.9) ysize(4) xsize(5.5) ///
xtitle("") bgcolor(white) graphregion(color(white))
graph export "$figdir/kaitz-index-cep-categories-2011-2019.pdf", as(pdf) replace

restore